using Common.Logging;
using System;
using System.Data;
namespace AppToolKit.Data
{
	public class DbSchemaHelper
	{
		private ILog logger_ = LogManager.GetLogger(typeof(DbSchemaHelper));
		private IDbProcessor database_;
		public IDbProcessor Database
		{
			get
			{
				return this.database_;
			}
			set
			{
				this.database_ = value;
			}
		}
		public DataTable GetSchemaTable(string sql)
		{
			sql = string.Format("set rowcount 1\n{0}\nset rowcount 0\n", sql);
			IDataReader dataReader = null;
			DataTable result;
			try
			{
				dataReader = this.Database.ExecuteReader(CommandType.Text, sql);
				DataTable schemaTable = dataReader.GetSchemaTable();
				result = schemaTable;
			}
			catch (Exception ex)
			{
				this.logger_.Debug(ex.Message);
				throw;
			}
			finally
			{
				if (dataReader != null)
				{
					dataReader.Close();
					dataReader.Dispose();
				}
			}
			return result;
		}
	}
}
